import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class Connector {
	public static String username = null;
	public static String password = null;
	public static String role = null;
	public static String driver = "com.mysql.jdbc.Driver"; // driver name
	public static String url = "jdbc:mysql://localhost/sport"; // URL to
																// database
																// server and
																// database name
	public static String mysql_username = "root"; // MySQL Username
	public static String mysql_password = "root"; // MySQL Password
	public static String sql_statement = null;
	public static Connection conn;
	public static Statement statement;
	public static ResultSet rs;

	public Connector(String sql) {
		try {
			prepare();
			sql_statement = sql;
		} catch (Exception e) {
			System.err.println("Mysql init error: " + e);
		}
	}

	public static void prepare() {
		try {
			Class.forName(driver); // load JDBC driver
			conn = DriverManager.getConnection(url, mysql_username,
					mysql_password);
			statement = conn.createStatement();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static void execute_sql() throws SQLException {
		if (statement != null) {
			statement.executeUpdate(sql_statement);
		} else
			return;
	}

	public static ResultSet execute() throws SQLException {
		if (statement != null) {
			return statement.executeQuery(sql_statement);
		} else
			return null;
	}

	public static void close() throws SQLException {
		rs.close();
		conn.close();
	}
}
